<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

define('MAILMAN2_BASEPATH_COMPONENTS', dirname(__FILE__).'/../../../components/com_mailman2');
define('MAILMAN2_BASEPATH_ADMINISTRATOR', dirname(__FILE__));

require_once($mainframe->getPath('admin_html'));
require_once(MAILMAN2_BASEPATH_COMPONENTS . '/functions.php');
// require_once(PMS_BASEPATH_ADMINISTRATOR . '/backend_authentification.php');
?>
<script language="JavaScript" src="../components/com_mailman2/functions.js" type="text/javascript"></script>
<?php

if(file_exists(MAILMAN2_BASEPATH_ADMINISTRATOR.'/language/'.$mosConfig_lang.'.php'))
   include_once(MAILMAN2_BASEPATH_ADMINISTRATOR.'/language/'.$mosConfig_lang.'.php');
else include_once(MAILMAN2_BASEPATH_ADMINISTRATOR.'/language/english.php');

require_once(MAILMAN2_BASEPATH_ADMINISTRATOR.'/language/english.php');

$my_id = $my->id;
$my_gid = $my->gid;

switch($task)
{
	case "save":
	saveConfig($option);
	break;
	case "cancel":
	showConfig($option);
	break;
	default:
	showConfig($option);
	break;
}

function saveConfig ($option) {
	$database = & JFactory::getDBO();;
	$values_in_db = array();
	$error_db = false;
	$query ="UPDATE #__mailman2 SET ";

	foreach($_POST AS $key=>$value)
	{
	if (strpos($key, 'mm_') === 0)
		{
			$query .= "" . substr($key, 3) ."='$value',";
		}
	}
	$query=substr($query, 0, -1);
	$query .=";";

	//store db-values in db

	$database->setQuery($query);
	if(!$database->query())
	{
		mailman2_sql_error($database->getErrorMsg());
		$error_db = true;
	}

	if($error_db) $mosmsg = _MM_MSG_SAVE_SETTINGS_ERROR;
	else $mosmsg = _MM_MSG_SAVE_SETTINGS_ALL;
	mosRedirect("index2.php?option=$option&act=config", $mosmsg);
}
function showConfig( $option ) {
  $database = & JFactory::getDBO(); $acl;
//  require_once(MAILMAN2_BASEPATH_ADMINISTRATOR.'/config.mailman2.php');

	$database->setQuery("SELECT * FROM #__mailman2 WHERE id='1'");
	if(!$database->query())
	{
		mailman2_sql_error($database->getErrorMsg());
		return false;
	}

	$rows = $database->loadObjectList();
	HTML_mailman2::editsettings($option, $rows);

?>

<?php
}

